package com.lfz.quality_effect.service.impl;

import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.metadata.Sheet;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lfz.quality_effect.mapper.TCivilStatisticsMapper;
import com.lfz.quality_effect.model.dto.FamilyTrialDTO;
import com.lfz.quality_effect.model.entity.TCivilStatistics;
import com.lfz.quality_effect.model.vo.CivilSettledVO;
import com.lfz.quality_effect.service.TCivilStatisticsService;
import com.lfz.quality_effect.utils.ExcelListener;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Service
public class TCivilStatisticsServiceImpl extends ServiceImpl<TCivilStatisticsMapper, TCivilStatistics> implements TCivilStatisticsService {
    /**
     * 上传民事收结存表
     * @param file
     * @return
     */
    @Override
    public void uploadCivilStatistics(MultipartFile file) {



        ExcelListener listener = new ExcelListener();
        InputStream inputStream ;
        try {
            inputStream = file.getInputStream();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        //传入参数
        ExcelReader excelReader = new ExcelReader(inputStream, null, listener);
        Sheet sheet = new Sheet(1, 4, FamilyTrialDTO.class);

        //读取信息
        excelReader.read(sheet);
        List<Object> objectList =listener.getDatas();

        System.out.println(objectList.size());

        List<TCivilStatistics> tList = new ArrayList<>();
        for (int i = 0; i < objectList.size(); i++) {
            FamilyTrialDTO familyTrialDTO = (FamilyTrialDTO) objectList.get(i);

//            System.out.println(familyTrialDTO);
//
//            TCivilStatistics tCivilStatistics = new TCivilStatistics();
//
//            tCivilStatistics.setCiviCaseNo(familyTrialDTO.getCiviCaseNo());
//            tCivilStatistics.setCauseAction(familyTrialDTO.getCauseAction());
//            tCivilStatistics.setFillDate(familyTrialDTO.getFillDate());
//            tCivilStatistics.setCourtRoom(familyTrialDTO.getCourtRoom());
//            tCivilStatistics.setCaseName(familyTrialDTO.getCaseName());
//            tCivilStatistics.setFillParty(familyTrialDTO.getFillParty());
//            tCivilStatistics.setUnderTake(familyTrialDTO.getUnderTake());
//            tCivilStatistics.setCreateTime(LocalDateTime.now());
//            tCivilStatistics.setClerk(familyTrialDTO.getClerk());
//            tCivilStatistics.setCloseCaseDate(familyTrialDTO.getCloseCaseDate());
//            tCivilStatistics.setCloseStyle(familyTrialDTO.getCloseStyle());
//            tCivilStatistics.setNewCloseStyle(familyTrialDTO.getNewCloseStyle());
//            tCivilStatistics.setMemberCollegiatePanel(familyTrialDTO.getMemberCollegiatePanel());
//            tCivilStatistics.setIsClosed(Objects.isNull(familyTrialDTO.getCloseCaseDate()) ? 0 : 1);
//
//            tList.add(tCivilStatistics);


        }

//        this.saveOrUpdateBatch(tList);

    }

    /**
     * 获取当前结案率
     * @return
     */
    @Override
    public CivilSettledVO getCurrentSettledRatio() {
        return this.getBaseMapper().getCurrentSettledRatio();
    }
}
